package com.lbagroup.giscovery;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.OverlayItem;
import com.lbagroup.giscovery.R;

/** 
 * Class for Google Map Layer
 * 
 * This class is a child class of the ItemizedOverlay class in the Android Maps library
 * This class helps to maintain the map overlay (i.e., a layer that holds marks and other special objects) 
 * 
 * @author XH
 * @version 2011.1107 
 * @since 0.1 
 */  
public class MapOverlay extends ItemizedOverlay {

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	Context mContext;
	//public MapActivity myActivity;
	public MapOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));

	}
	
	public MapOverlay(Drawable defaultMarker, Context context) {
		//super(defaultMarker);
		super(boundCenterBottom(defaultMarker));
		mContext = context;

	}
	protected boolean onTap(int index) {
		  OverlayItem item = mOverlays.get(index);
		  
    Intent intent = new Intent(); 
          intent.setClassName(mContext, DetailPOI.class.getName());
          intent.putExtra("title", item.getTitle());
          intent.putExtra("content", item.getSnippet());
          mContext.startActivity(intent);       
		  return true;
		}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	@Override
	protected OverlayItem createItem(int arg0) {
		return mOverlays.get(arg0);

	}

	@Override
	public int size() {
		return mOverlays.size();

	}
	public void clearall(){
		if(mOverlays.size()>0){
			mOverlays.clear();
		}
	}
}
